package com.edu.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.eduservice.client.VodClient;
import com.edu.eduservice.domain.EduVideo;
import com.edu.eduservice.mapper.EduVideoMapper;
import com.edu.eduservice.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author ljw
 * @since 2022-09-16
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    private VodClient vodClient;
    //TODO 删除小节并且删除视屏
    @Override
    public void delVideo(String id) {
        //添加条件
        QueryWrapper<EduVideo> wrapper=new QueryWrapper<>();
        wrapper.eq("course_id",id);

        //删除视频
        List<EduVideo> eduVideos = baseMapper.selectList(wrapper);

        List vidList=new ArrayList();
        for (EduVideo eduVideo : eduVideos) {
            if(!String.valueOf(eduVideo.getVideoSourceId()).equals("null")) {
                vidList.add(eduVideo.getVideoSourceId());
            }
        }
        //如果一个数据都没有就不删除视频
        if(vidList.size()>0){
            //删除多个
            vodClient.delmany(vidList);
        }

        //删除
        baseMapper.delete(wrapper);
    }
}
